package com.bruan.Stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class StreamTest {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Collections.addAll(list,"山的1","山的2","张无忌","张三丰","山的5","山的6","山的7");
        System.out.println(list);
        //1.
        List<String> list1 = new ArrayList<>();
        for (String s : list) {
            if (s.length()==3&&s.startsWith("张")){
                list1.add(s);
            }
        }
        System.out.println(list1);
        //2.
        List<String> list2 = list.stream().filter(s -> s.startsWith("张")).filter(s->s.length()==3)
                .collect(Collectors.toList());
        System.out.println(list2);
    }
}
